package typistcal.executor;

import java.util.logging.Level;
import java.util.logging.Logger;

//@author A0105493H
public class Utility {
	private static final Logger LOGGER = Logger.getLogger(Utility.class
			.getName());

	// @author A0096911Y
	public static String capitaliseWord(String word) {
		word = word.toLowerCase();
		char[] wordInCharArray = word.toCharArray();
		wordInCharArray[0] = Character.toUpperCase(wordInCharArray[0]);
		return new String(wordInCharArray);
	}

	public static boolean isDivisibleBy(int year, int number) {
		return (year % number == 0);
	}

	public static boolean isStringInList(String str, String[] list) {
		for (int i = 0; i < list.length; i++) {
			if (str.equalsIgnoreCase(list[i])) {
				return true;
			}
		}
		return false;
	}

	public static boolean isInteger(String num) {
		try {
			Integer.parseInt(num);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	// @author A0105493H
	public static boolean isMultipleLines(String wholeLine) {

		if (wholeLine.contains("\n")) {
			return true;
		} else {
			return false;
		}
	}

	public static String convertIntArrayToString(int[] lineNumber) {
		int index = 0;
		StringBuilder sb = new StringBuilder();
		try {
			while (index < lineNumber.length) {
				Integer inte = new Integer(lineNumber[index]);
				sb.append(inte.toString() + " ");
				index++;
			}
		} catch (IndexOutOfBoundsException e) {
			LOGGER.log(Level.SEVERE, "wrong lineNumber format!");
		}
		return sb.toString();
	}

}
